package com.stargate.soft.transaction.pointaccesbatiment;

import java.sql.SQLException;

import com.stargate.bd.ConnectionBD;
import com.stargate.bd.dao.factory.PointAccesBatimentDAO;
import com.stargate.exception.UnSeulPointAccesBatimentException;
import com.stargate.io.LectureClavier;

public class SuppressionPointAccesBatiment {

	private String codePointAcces;

	public SuppressionPointAccesBatiment() throws SQLException,
			UnSeulPointAccesBatimentException {
		ConnectionBD.setSerializable();
		init();
		ConnectionBD.commit();
	}

	private void init() throws SQLException, UnSeulPointAccesBatimentException {
		System.out.print("Code du point d'accès : ");
		codePointAcces = LectureClavier.lireChaine();
		PointAccesBatimentDAO pointAccesBatimentDAO = new PointAccesBatimentDAO();
		try {
			pointAccesBatimentDAO.delete(codePointAcces);
		} catch (SQLException e) {
			if (e.getErrorCode() == UnSeulPointAccesBatimentException.ERROR_CODE) {
				throw new UnSeulPointAccesBatimentException(e.getMessage());
			} else {
				throw e;
			}
		}
	}

	public String getCodePointAcces() {
		return codePointAcces;
	}

}
